#!/bin/sh

PICOLIBC_DIR=/build/picolibc
GLIBC_DIR=/build/glibc

set -e

#test=echo

options="-Dwant-math-errno=true -Dio-long-double=true -Dwerror=true -Dmb-capable=true -Dmb-extended-charsets=true"
minoptions="$options"
reloptions="$options --buildtype=release -Dbuild-type-subdir=release -Dwerror=true"

for arch in arm riscv; do

    DIR=$PICOLIBC_DIR/builds/build-$arch-minsize

    $test rm -rf $DIR
    $test mkdir -p $DIR
    $test cd $DIR

    echo '###################################'
    echo '####' ../../scripts/do-$arch-configure $options
    echo '###################################'

    $test ../../scripts/do-$arch-configure $options
    $test ninja test install

    DIR=$PICOLIBC_DIR/builds/build-$arch-release

    $test rm -rf $DIR
    $test mkdir -p $DIR
    $test cd $DIR

    echo '###################################'
    echo '####' ../../scripts/do-$arch-configure $reloptions
    echo '###################################'

    $test ../../scripts/do-$arch-configure $reloptions
    $test ninja test install

done

options="-Dwerror=true"
minoptions="$options --buildtype=minsize"
reloptions="$options --buildtype=release -Dpicolibc-buildtype=release"

for arch in arm riscv; do

    DIR=$GLIBC_DIR/builds/build-$arch-minsize

    $test rm -rf $DIR
    $test mkdir -p $DIR
    $test cd $DIR

    echo '###################################'
    echo '####' ../../picolibc/do-$arch-configure $minoptions
    echo '###################################'

    $test ../../picolibc/do-$arch-configure $minoptions
    $test ninja test

    DIR=$GLIBC_DIR/builds/build-$arch-release

    $test rm -rf $DIR
    $test mkdir -p $DIR
    $test cd $DIR

    echo '###################################'
    echo '####' ../../picolibc/do-$arch-configure $reloptions
    echo '###################################'

    $test ../../picolibc/do-$arch-configure $reloptions
    $test ninja test

done
